//
//  HCMineAsksViewController.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/18.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCMineAsksViewController.h"

#import "HCMineAsksView.h"

#import "HCMineAskedModel.h"

@interface HCMineAsksViewController () <HCMineAskedUploadDelegate> {
    HCMineAskedModel *askedModel;
    HCMineAsksView *asksView;
}

@end

@implementation HCMineAsksViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.textTitle = @"我的提问";
    
    asksView = [[HCMineAsksView alloc] initWithFrame:CGRectMake(0, 0, self.centerView.frame.size.width, self.centerView.frame.size.height)];
    asksView.delegate = self;
    [self.centerView addSubview:asksView];
    
    self.dataRequest.delegate = self;
    [self.dataRequest postHC_MineAsked:HCGETUSER(@"userid")];
    
    // Do any additional setup after loading the view.
}

-(void)answerUpload:(NSIndexPath *)indexPath lastIndexPath:(NSIndexPath *)indexPath_l{
    HCMineAskedData *data = askedModel.myask[indexPath_l.row];
    HCMineAskedDataAnswer *answer = data.answer[indexPath.row];
    [self.dataRequest postHC_Choose:answer.hc_id];
}

-(void)dataRequesterFail:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveErrorDictionary:(NSDictionary *)dictionary {
    NSLog(@"我的提问网络请求失败");
}

-(void)dataRequesterFinish:(DataRequester *)requester requesterWithType:(DataRequestType)aType receiveDictionary:(NSDictionary *)dictionary {

    if (aType == HC_MINEASKEDINDEX_TYPE) {
        NSLog(@"我的提问请求:%@",dictionary);
        askedModel = [[HCMineAskedModel alloc] initWithDictionary:dictionary error:nil];
        asksView.model = askedModel;
    }else{
        if ([dictionary[@"stat"] integerValue] == 200) {
            [XHToast showBottomWithText:@"采纳成功"];
        }else{
            [XHToast showBottomWithText:@"采纳失败"];
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
